package cn.anlab.anappframe.demo.adapter;

import java.util.List;
import java.util.Map;

import cn.anlab.anappframe.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;
/**
 * 列表对话框中列表的Adapter
 * 
 * @version 1.0
 * @author Stan Rong 2012-3-6
 */
public class ListViewAdapter extends BaseAdapter {

	private Context context;
	private List<Map<String, String>> dataList;
	private String textKey;
	LayoutInflater inflater;

	public ListViewAdapter(Context context, List<Map<String, String>> dataList, String textKey) {
		this.context = context;
		this.dataList = dataList;
		this.textKey = textKey;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.comp_listdialog_item, null);
		}
		Map<String, String> map = (Map<String, String>)getItem(position);
		TextView tv = (TextView)convertView.findViewById(R.id.comp_listdialog_text);
		RadioButton radio = (RadioButton)convertView.findViewById(R.id.comp_listdialog_radio);
		setItemData(map, tv);
		return convertView;
	}
	
	/**
	 * 设置每行的文本内容 <br/>
	 * 可重写此方法，去给每行的文本赋值
	 * @param rowData
	 * @param tv
	 */
	protected void setItemData(Map<String, String> rowData, TextView tv) {
		tv.setText(rowData.get(textKey));
	}

	public List<Map<String, String>> getDataList() {
		return dataList;
	}
	
	

}
